import java.util.Scanner;

//题目：求一个3*3矩阵对角线元素之和
public class Test29 {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        System.out.println("请输入九个数");
        int[][] arr = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                arr[i][j] = console.nextInt();
            }
        }
        System.out.println("3*3矩阵:");
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
        int counta = 0;
        int countb = 0;
        for (int i = 0; i < 3; i++) {
            counta += arr[i][i];
            countb += arr[2 - i][i];
        }
        System.out.println("主对角线元素和为：" + counta);
        System.out.println("副对角线元素和为：" + countb);
    }
}
